﻿using System.Collections;

namespace 热更验证
{
    class HashK<Tkey,Tvalue> :Hashtable
    {
        /// <summary>
        /// 通过键获取值
        /// </summary>
        /// <returns>返回对应类型的值</returns>
        public Tvalue GetTvalue(Tkey key)
        {
            if (this.ContainsKey(key))
            {
                Tvalue value = (Tvalue)this[key];
                return value;
            }
            else
            {
                return default;
            }
        }

        /// <summary>
        /// 通过值获取键
        /// </summary>
        /// <returns>返回对应类型的键</returns>
        public Tkey GetTkey(Tvalue value)
        {
            Tkey key = default;
            if (this.ContainsValue(value))
            {
                foreach (Tkey k in this.Keys)
                {
                    if (this[k].Equals(value))
                    {
                        key = k;
                        break;
                    }
                }
                return key;
            }
            else
            {
                return default;
            }
        }
    }
}
